<template>
  <div class="content-wrapper">
    <!-- <div class="content-header">浏览历史</div> -->
    <div class="content-container">
      <div>
        <el-table
          height="500"
          v-loading="listLoading"
          :data="pageList"
          @row-click="openDocument"
        >
          <el-table-column label="文档名称">
            <template slot-scope="scope">
              <svg class="icon iconcalss" aria-hidden="true">
                <use
                  :xlink:href="iconType(scope.row.fileExtension).class"
                ></use>
              </svg>
              <span style="cursor: pointer"
                >{{ scope.row.documentName }}{{ scope.row.fileExtension }}</span
              >
            </template>
          </el-table-column>
          <el-table-column
            label="访问时间"
            prop="accessTimeString"
            width="160px"
          />
          <el-table-column label="访问类型" prop="accessType" width="160px">
            <template scope="{row}">
              <span v-if="row.accessType == 1">编辑</span>
              <span v-else>阅读</span>
            </template>
          </el-table-column>
          <el-table-column label="文件状态" prop="status" width="160px">
            <template scope="{row}">
              <el-tag v-if="!row.documentNotExist" type="success">正常</el-tag>
              <el-tag v-else type="danger">已删除</el-tag>
            </template>
          </el-table-column>
        </el-table>
      </div>
      <pagination
        v-show="total > 0"
        :total="total"
        :page-number.sync="listQuery.pageNumber"
        :page-size.sync="listQuery.pageSize"
        @pagination="getList"
      />
    </div>
  </div>
</template>
<script>
import { pageDocumentHistory } from '@/api/xd/recent'
import Pagination from '@/components/Pagination'
import { unity } from '@/styles/js/setIconType.js'
import { historyDelete } from '@/api/fd/document.js'

export default {
  components: {
    Pagination
  },
  data() {
    return {
      iconType: unity.setIconType,
      listLoading: false,
      pageList: [],
      listQuery: {
        documentName: '',
        pageNumber: 1,
        pageIndex: 0,
        pageSize: 10
      },
      total: 0
    }
  },
  mounted() {
    this.getList()
  },
  methods: {
    openDocument(row) {
      if (row.documentNotExist) {
        this.$message.info('当前分享的源数据已经被删除')
        historyDelete({
          documentHistoryId: row.documentHistoryId
        }).then(() => {
          this.getList()
        })
        return
      }
      var mode = row.accessType == 0 ? 'view' : 'edit'
      window.open(
        'onlyoffice/createDocument.html?&token=' +
          this.$store.getters.token +
          '&documentId=' +
          row.documentId +
          '&mode=' +
          mode +
          '&urldata=' +
          process.env.VUE_APP_BASE_API
      )
    },
    getList() {
      this.listLoading = true
      this.listQuery.pageIndex = this.listQuery.pageNumber - 1
      pageDocumentHistory(this.listQuery).then((res) => {
        this.pageList = res.data.rows
        this.total = res.data.total
        this.listLoading = false
      })
    }
  }
}
</script>
